package com.tul.vapp.servicecenter.util;

import java.util.Locale;
import java.util.ResourceBundle;

import com.tul.cusa.common.log.LogTracerFactory;
import com.tul.cusa.common.log.intf.ILogTracer;
import com.tul.cusa.common.util.StringUtil;
import com.tul.vapp.servicecenter.common.SysConfigConstant;


/**
 * Created by jyliu on 2016/10/30.
 */
public class I18nUtil {
	/**
	 * 日志
	 */
	private static final ILogTracer TRACER = LogTracerFactory.getTracer(I18nUtil.class);
	/**
	 * 组件语言
	 */
	private static final String APP_LOCALE_STR = SysConfigUtil.getProperty(SysConfigConstant.LANGUAGE,
			SysConfigConstant.DEFAULT_LANGUAGE);
	/**
	 * 组件语言对象
	 */
	private static final Locale APP_LOCALE = new Locale(APP_LOCALE_STR.split("_")[0],
			APP_LOCALE_STR.split("_")[1]);

	/**
	 * 获取组件语言对象
	 * 
	 * @return locale
	 */
	public static Locale getLocale() {
		return APP_LOCALE;
	}

	/**
	 * 获取组件语言
	 * 
	 * @return String
	 */
	public static String getLocaleStr() {
		return APP_LOCALE_STR;
	}

	/**
	 * 获取资源文件的值
	 * 
	 * @param resPath 资源路径
	 * @param key key
	 * @return string
	 */
	public static String getResource(String resPath, String key) {
		return getResource(resPath, key, I18nUtil.getLocale());
	}

	/**
	 * 获取资源文件的值
	 * 
	 * @param resPath 资源路径
	 * @param key key
	 * @param locale 语言
	 * @return string
	 */
	public static String getResource(String resPath, String key, Locale locale) {
		ResourceBundle appResource = ResourceBundle.getBundle(resPath, locale);
		return StringUtil.replaceNull(appResource.getString(key));
	}
}
